<?php
/**
 * @author Zwc
 * Created On 2021/3/9 21:58
 */

namespace app\auth\controller;


use app\auth\service\GroupService;
use app\common\controller\AdminBaseController;

class Group extends AdminBaseController
{
    /**
     * 跳转到列表页面
     * @return \think\response\View
     */
    public function index() {
        return view('index');
    }

    /**
     * 获取数据
     */
    public function getData() {
        $params = $this->request->get();
        $service = new GroupService();
        $datas = $service->getData($params);
        return ['code' => 0,'msg' => '获取数据成功','count' => $datas['count'],'data' => $datas['data']];
    }

    /**
     * 添加
     */
    public function add() {
        if($this->request->isPost()) {
            $params = $this->request->post();
            $groupService = new GroupService();
            $res = $groupService->add($params);
            return $res;
        }else {
            return view('add');
        }
    }

    public function edit($id) {
        if($this->request->isPost()) {
            $params = $this->request->post();
            $groupService = new GroupService();
            $res = $groupService->edit($params);
            return $res;
        }else {
            $service = new GroupService();
            $detail = $service->detail($id);
            return view('edit',[
                'data' => $detail
            ]);
        }
    }

    public function del($id) {
        $service = new GroupService();
        $res = $service->del($id);
        return $res;
    }
}